#include <stdio.h>
unsigned long factorial (int);
float combinacion(int n, int i);
float combinacion2(int n, int i);

int main (int argc, char* argv[]) {
	int n, i;
	printf("n = ");
	scanf("%d", &n);
	printf("n! = %lu\n\n", factorial(n));
	for (i = 0; i <= n; i++) {
		printf("Combinacion C(%d, %i) = %g\t%g\n", n, i, combinacion(n, i), combinacion2(n, i));
	}
	return 0;
}

unsigned long factorial (int n) {
	unsigned long r = 1;
	int i;
	if (n >= 2) {
		for (i = 2; i <= n; i++) {
			r *= i;
		}
	} else {
		r = 1;
	}
	return r;
}

float combinacion(int n, int i) {
	float r = 1.0;
	
	if (n >= i) {
		r = (float) factorial(n) / ((float) factorial(i) * (float) factorial(n - i));
	} else {
		r = 0.0;
	}
	
	return r;
}

float combinacion2(int n, int i) {
	float r = 1.0;
	int k;
	
	if (n >= i) {
		for (k = 0; k <= i - 1; k++) {
			r *= ((float)(n - k)/(float)(i - k));
		}
	} else {
		r = 0.0;
	}
	
	return r;
}
